/*
 * Copyright (c) ShaoxiongDu <Shaoxiong.dev@aliyun.com> 2021 all Rights Reserved
 */

package zh.codegym.task.task08.task0817;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import static java.util.Map.Entry;

/* 
我们不需要重复的内容
*/

public class Solution {
    public static HashMap<String, String> createMap() {
        //在此编写你的代码
        HashMap<String, String> map = new HashMap<>();
        map.put("1", "1");
        map.put("2", "1");
        map.put("3", "1");
        map.put("4", "2");
        map.put("5", "3");
        map.put("6", "4");
        map.put("7", "1");
        map.put("8", "1");
        map.put("9", "1");
        map.put("10", "1");

        return map;

    }

    public static void removeFirstNameDuplicates(Map<String, String> map) {
        //在此编写你的代码

        HashMap<String, String> copy = new HashMap<String, String>(map);
        Iterator<Entry<String, String>> iter = copy.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<String, String> pair = iter.next();
            String name = pair.getValue();
            iter.remove();
            if (copy.containsValue(name)) {
                removeItemFromMapByValue(map, name);
            }
        }

    }

    public static void removeItemFromMapByValue(Map<String, String> map, String value) {
        HashMap<String, String> copy = new HashMap<String, String>(map);
        for (Map.Entry<String, String> pair : copy.entrySet()) {
            if (pair.getValue().equals(value)) {
                map.remove(pair.getKey());
            }
        }
    }

    public static void main(String[] args) {

    }
}
